package androidx.databinding;

import android.annotation.TargetApi;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.SparseIntArray;
import android.view.Choreographer;
import android.view.Choreographer.FrameCallback;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import o.jg;
import o.ji;
import o.jk;
import o.jm;
import o.jp;
import o.kv;

public abstract class ViewDataBinding extends jg {
    private static final o.ji.a<jp, ViewDataBinding, Void> ʻ = new o.ji.a<jp, ViewDataBinding, Void>() {
        public void ˊ(jp jpVar, ViewDataBinding viewDataBinding, int i, Void voidR) {
            switch (i) {
                case 1:
                    if (!jpVar.ˎ(viewDataBinding)) {
                        viewDataBinding.ˊॱ = true;
                        return;
                    }
                    return;
                case 2:
                    jpVar.ˊ(viewDataBinding);
                    return;
                case 3:
                    jpVar.ˏ(viewDataBinding);
                    return;
                default:
                    return;
            }
        }
    };
    private static final a ʼ = new a() {
    };
    private static final a ʽ = new a() {
    };
    static int ˊ = VERSION.SDK_INT;
    private static final int ˋ = "binding_".length();
    private static final boolean ˏ = (ˊ >= 16);
    private static final OnAttachStateChangeListener ˏॱ;
    private static final a ॱ = new a() {
    };
    private static final a ॱॱ = new a() {
    };
    private static final ReferenceQueue<ViewDataBinding> ᐝ = new ReferenceQueue();
    private final FrameCallback ʻॱ;
    private Handler ʽॱ;
    private kv ʾ;
    private ViewDataBinding ʿ;
    private boolean ˊॱ = false;
    private boolean ˋॱ = false;
    protected final jk ˎ;
    private final Runnable ͺ = new Runnable(this) {
        final /* synthetic */ ViewDataBinding ˋ;

        {
            this.ˋ = r1;
        }

        public void run() {
            synchronized (this) {
                this.ˋ.ˋॱ = false;
            }
            ViewDataBinding.ʽ();
            if (VERSION.SDK_INT < 19 || this.ˋ.ॱᐝ.isAttachedToWindow()) {
                this.ˋ.ˋ();
                return;
            }
            this.ˋ.ॱᐝ.removeOnAttachStateChangeListener(ViewDataBinding.ˏॱ);
            this.ˋ.ॱᐝ.addOnAttachStateChangeListener(ViewDataBinding.ˏॱ);
        }
    };
    private b[] ॱˊ;
    private ji<jp, ViewDataBinding, Void> ॱˋ;
    private boolean ॱˎ;
    private final View ॱᐝ;
    private Choreographer ᐝॱ;

    interface a {
    }

    static class b<T> extends WeakReference<ViewDataBinding> {
        private final d<T> ˊ;
        private T ˎ;

        public boolean ˊ() {
            boolean z = false;
            if (this.ˎ != null) {
                this.ˊ.ˋ(this.ˎ);
                z = true;
            }
            this.ˎ = null;
            return z;
        }
    }

    public static class c {
        public final int[][] ˋ;
        public final String[][] ˎ;
        public final int[][] ˏ;
    }

    interface d<T> {
        void ˋ(T t);
    }

    public abstract boolean ˎ();

    protected abstract void ˏ();

    static {
        if (VERSION.SDK_INT < 19) {
            ˏॱ = null;
        } else {
            ˏॱ = new OnAttachStateChangeListener() {
                @TargetApi(19)
                public void onViewAttachedToWindow(View view) {
                    ViewDataBinding.ˎ(view).ͺ.run();
                    view.removeOnAttachStateChangeListener(this);
                }

                public void onViewDetachedFromWindow(View view) {
                }
            };
        }
    }

    protected ViewDataBinding(jk jkVar, View view, int i) {
        this.ˎ = jkVar;
        this.ॱˊ = new b[i];
        this.ॱᐝ = view;
        if (Looper.myLooper() == null) {
            throw new IllegalStateException("DataBinding must be created in view's UI Thread");
        } else if (ˏ) {
            this.ᐝॱ = Choreographer.getInstance();
            this.ʻॱ = new FrameCallback(this) {
                final /* synthetic */ ViewDataBinding ˎ;

                {
                    this.ˎ = r1;
                }

                public void doFrame(long j) {
                    this.ˎ.ͺ.run();
                }
            };
        } else {
            this.ʻॱ = null;
            this.ʽॱ = new Handler(Looper.myLooper());
        }
    }

    protected void ˏ(View view) {
        view.setTag(o.jq.a.ˏ, this);
    }

    public void ˋ() {
        if (this.ʿ == null) {
            ʻ();
        } else {
            this.ʿ.ˋ();
        }
    }

    private void ʻ() {
        if (this.ॱˎ) {
            ˊ();
        } else if (ˎ()) {
            this.ॱˎ = true;
            this.ˊॱ = false;
            if (this.ॱˋ != null) {
                this.ॱˋ.ˎ(this, 1, null);
                if (this.ˊॱ) {
                    this.ॱˋ.ˎ(this, 2, null);
                }
            }
            if (!this.ˊॱ) {
                ˏ();
                if (this.ॱˋ != null) {
                    this.ॱˋ.ˎ(this, 3, null);
                }
            }
            this.ॱˎ = false;
        }
    }

    static ViewDataBinding ˎ(View view) {
        if (view != null) {
            return (ViewDataBinding) view.getTag(o.jq.a.ˏ);
        }
        return null;
    }

    @NonNull
    public View ॱ() {
        return this.ॱᐝ;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    protected void ˊ() {
        /*
        r2 = this;
        r0 = r2.ʿ;
        if (r0 == 0) goto L_0x000a;
    L_0x0004:
        r0 = r2.ʿ;
        r0.ˊ();
    L_0x0009:
        return;
    L_0x000a:
        monitor-enter(r2);
        r0 = r2.ˋॱ;	 Catch:{ all -> 0x0011 }
        if (r0 == 0) goto L_0x0014;
    L_0x000f:
        monitor-exit(r2);	 Catch:{ all -> 0x0011 }
        goto L_0x0009;
    L_0x0011:
        r0 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x0011 }
        throw r0;
    L_0x0014:
        r0 = 1;
        r2.ˋॱ = r0;	 Catch:{ all -> 0x0011 }
        monitor-exit(r2);	 Catch:{ all -> 0x0011 }
        r0 = r2.ʾ;
        if (r0 == 0) goto L_0x002e;
    L_0x001c:
        r0 = r2.ʾ;
        r0 = r0.ac_();
        r0 = r0.ˋ();
        r1 = o.kp.c.STARTED;
        r0 = r0.ˏ(r1);
        if (r0 == 0) goto L_0x0009;
    L_0x002e:
        r0 = ˏ;
        if (r0 == 0) goto L_0x003a;
    L_0x0032:
        r0 = r2.ᐝॱ;
        r1 = r2.ʻॱ;
        r0.postFrameCallback(r1);
        goto L_0x0009;
    L_0x003a:
        r0 = r2.ʽॱ;
        r1 = r2.ͺ;
        r0.post(r1);
        goto L_0x0009;
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.databinding.ViewDataBinding.ˊ():void");
    }

    protected static Object[] ॱ(jk jkVar, View view, int i, c cVar, SparseIntArray sparseIntArray) {
        Object[] objArr = new Object[i];
        ˏ(jkVar, view, objArr, cVar, sparseIntArray, true);
        return objArr;
    }

    private static void ˏ(jk jkVar, View view, Object[] objArr, c cVar, SparseIntArray sparseIntArray, boolean z) {
        if (ˎ(view) == null) {
            String str;
            int lastIndexOf;
            int ॱ;
            int i;
            Object tag = view.getTag();
            if (tag instanceof String) {
                str = (String) tag;
            } else {
                str = null;
            }
            tag = null;
            if (z && str != null && str.startsWith("layout")) {
                int i2;
                lastIndexOf = str.lastIndexOf(95);
                if (lastIndexOf <= 0 || !ˋ(str, lastIndexOf + 1)) {
                    i2 = -1;
                } else {
                    ॱ = ॱ(str, lastIndexOf + 1);
                    if (objArr[ॱ] == null) {
                        objArr[ॱ] = view;
                    }
                    if (cVar == null) {
                        ॱ = -1;
                    }
                    i2 = ॱ;
                    tag = 1;
                }
                i = i2;
            } else if (str == null || !str.startsWith("binding_")) {
                i = -1;
            } else {
                ॱ = ॱ(str, ˋ);
                if (objArr[ॱ] == null) {
                    objArr[ॱ] = view;
                }
                if (cVar == null) {
                    ॱ = -1;
                }
                i = ॱ;
                ॱ = 1;
            }
            if (tag == null) {
                ॱ = view.getId();
                if (ॱ > 0 && sparseIntArray != null) {
                    ॱ = sparseIntArray.get(ॱ, -1);
                    if (ॱ >= 0 && objArr[ॱ] == null) {
                        objArr[ॱ] = view;
                    }
                }
            }
            if (view instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view;
                int childCount = viewGroup.getChildCount();
                int i3 = 0;
                int i4 = 0;
                while (i4 < childCount) {
                    int i5;
                    int i6;
                    View childAt = viewGroup.getChildAt(i4);
                    if (i >= 0 && (childAt.getTag() instanceof String)) {
                        String str2 = (String) childAt.getTag();
                        if (str2.endsWith("_0") && str2.startsWith("layout") && str2.indexOf(47) > 0) {
                            int ˋ = ˋ(str2, i3, cVar, i);
                            if (ˋ >= 0) {
                                tag = 1;
                                i3 = ˋ + 1;
                                i5 = cVar.ˏ[i][ˋ];
                                ˋ = cVar.ˋ[i][ˋ];
                                lastIndexOf = ˊ(viewGroup, i4);
                                if (lastIndexOf == i4) {
                                    objArr[i5] = jm.ˊ(jkVar, childAt, ˋ);
                                    i5 = i4;
                                    i6 = i3;
                                } else {
                                    i6 = (lastIndexOf - i4) + 1;
                                    View[] viewArr = new View[i6];
                                    for (lastIndexOf = 0; lastIndexOf < i6; lastIndexOf++) {
                                        viewArr[lastIndexOf] = viewGroup.getChildAt(i4 + lastIndexOf);
                                    }
                                    objArr[i5] = jm.ˎ(jkVar, viewArr, ˋ);
                                    i5 = (i6 - 1) + i4;
                                    i6 = i3;
                                }
                                if (tag == null) {
                                    ˏ(jkVar, childAt, objArr, cVar, sparseIntArray, false);
                                }
                                i4 = i5 + 1;
                                i3 = i6;
                            }
                        }
                    }
                    tag = null;
                    i5 = i4;
                    i6 = i3;
                    if (tag == null) {
                        ˏ(jkVar, childAt, objArr, cVar, sparseIntArray, false);
                    }
                    i4 = i5 + 1;
                    i3 = i6;
                }
            }
        }
    }

    private static int ˋ(String str, int i, c cVar, int i2) {
        CharSequence subSequence = str.subSequence(str.indexOf(47) + 1, str.length() - 2);
        String[] strArr = cVar.ˎ[i2];
        int length = strArr.length;
        for (int i3 = i; i3 < length; i3++) {
            if (TextUtils.equals(subSequence, strArr[i3])) {
                return i3;
            }
        }
        return -1;
    }

    private static int ˊ(ViewGroup viewGroup, int i) {
        String str = (String) viewGroup.getChildAt(i).getTag();
        String substring = str.substring(0, str.length() - 1);
        int length = substring.length();
        int childCount = viewGroup.getChildCount();
        int i2 = i + 1;
        int i3 = i;
        while (i2 < childCount) {
            int i4;
            View childAt = viewGroup.getChildAt(i2);
            String str2 = childAt.getTag() instanceof String ? (String) childAt.getTag() : null;
            if (str2 != null && str2.startsWith(substring)) {
                if (str2.length() == str.length() && str2.charAt(str2.length() - 1) == '0') {
                    break;
                } else if (ˋ(str2, length)) {
                    i4 = i2;
                    i2++;
                    i3 = i4;
                }
            }
            i4 = i3;
            i2++;
            i3 = i4;
        }
        return i3;
    }

    private static boolean ˋ(String str, int i) {
        int length = str.length();
        if (length == i) {
            return false;
        }
        while (i < length) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
            i++;
        }
        return true;
    }

    private static int ॱ(String str, int i) {
        int i2 = 0;
        while (i < str.length()) {
            i2 = (i2 * 10) + (str.charAt(i) - 48);
            i++;
        }
        return i2;
    }

    private static void ʽ() {
        while (true) {
            Reference poll = ᐝ.poll();
            if (poll == null) {
                return;
            }
            if (poll instanceof b) {
                ((b) poll).ˊ();
            }
        }
    }
}
